package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Dept;
import com.itheima.pojo.Emp;
import com.itheima.service.DeptService;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public void removeDeptById(Integer id) {
        //先判断该部门下是否有员工
        List<Emp> list = empMapper.selectList(new LambdaQueryWrapper<Emp>().eq(Emp::getId, id));
        if (list != null && list.size() > 0) {
            throw new RuntimeException("部门下有员工不能删除");
        }
        this.removeById(id);
    }
}
